<template>
  <a-modal v-bind="$attrs" title="编辑公告" :width="400" :mask="false" centered :maskClosable="false" :destroyOnClose="true" @cancel="cancelHandler">
      <a-form-model :model="configForm" :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }">
        <!-- <a-form-model-item label="宽">
          <a-input v-model="configForm.width" />
        </a-form-model-item> -->
        <a-form-model-item label="最大条数">
          <a-input v-model="configForm.num" />
        </a-form-model-item>
      </a-form-model>
      <div slot="footer">
        <a-button @click="cancelHandler">取消</a-button>
        <a-button type="primary" @click="okHandler">确认</a-button>
      </div>
    </a-modal>
</template>
<script>
import { setPersonalConfig } from '@/api/devportalApi.js'
export default {
  name: 'NoticeConfigModal',
  props: {
    resFuncData: {
      type: Array,
      defualt: () => []
    },
    workSpaceItem: {
      type: Object,
      defualt: () => ({})
    }
  },
  data () {
    return {
      configForm: {
        width: '',
        num: ''
      }
    }
  },
  methods: {
    cancelHandler () {
      this.$set(this.configForm, 'num', '')
      this.$emit('cancel')
    },
    okHandler () {
      
      if (!this.configForm.num || !Number(this.configForm.num)) {
        return this.$message.warning('请填写大于0的最大条数')
      }
      let { width, moduleId, moduleName, workspaceId, workspaceName } = this.workSpaceItem
      let submitData = {
        // contentSortList,
        num: this.configForm.num,
        width,
        moduleId,
        moduleName,
        workspaceId,
        workspaceName
      }
      // console.log(submitData)
      let method = this.workSpaceItem.personalConfig && this.workSpaceItem.personalConfig.contentSortList.length !== 0 ? 'put' : 'post'
      if (method === 'put') {
        submitData.objectVersionNumber = this.workSpaceItem.personalConfig.objectVersionNumber
        submitData._token = this.workSpaceItem.personalConfig._token
        submitData.id = this.workSpaceItem.personalConfig.id
      }
      setPersonalConfig(method, submitData).then(res => {
        if (res.status === 200) {
          this.$set(this.configForm, 'num', '')
          this.$emit('ok')
        }
      })
    }
  },
  mounted () {
  },
  watch: {
    '$attrs.visible' (status) {
      if (status) {
        if (this.workSpaceItem.personalConfig) {
          this.$set(this.configForm, 'num', this.workSpaceItem.personalConfig.num)
        }
      }
    }
  }
}
</script>
<style lang="less" scoped>
.portal-draggable-tree {
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  /deep/li .ant-tree-node-content-wrapper {
    .custom-title-box {
      .swap-icon {
        color: #5e83ff;
        display: none;
        transform: rotate(90deg);
        float: right;
        margin-top: 2px;
      }
    }
    &:hover {
      .swap-icon {
        display: block;
      }
    }
  }
  /deep/li .ant-tree-node-content-wrapper.ant-tree-node-selected {
    background-color: transparent;
  }
}
</style>